// 从外面的window引进需要的变量和方法
var generateUUID = window.parent.generateUUID;
var traceOrigin = window.parent.traceOrigin;
String.prototype.htmlEscape = window.parent.String.prototype.htmlEscape;

$('#rowValue, #columnValue').on('input', function (e) {
    this.value = this.value.replace(/\D/g, '');
});
$('#rowValue, #columnValue').on('change', function (e) {
    this.value = Math.min(this.value, 20);
    this.value = Math.max(this.value, 1);
});
$('.spinner-arrow-up').on('click', function () {
    var input = $(this).parents('span').find('input');
    input.val(Math.min(input.val() - -1, 20));
});
$('.spinner-arrow-down').on('click', function () {
    var input = $(this).parents('span').find('input');
    input.val(Math.max(input.val() - 1, 1));
});

dialog.onok = function () {
    var rowValue = $("#rowValue").val();
    var columnValue = $("#columnValue").val();
    var describe = $("#tableName").val();

    editor.execCommand('InsertTable', {
        numRows: rowValue,
        numCols: columnValue,
        describe: describe.htmlEscape()
    });
    return this.oncancel();
}

dialog.oncancel = function () {
    $('#rowValue').val('1');
    $('#columnValue').val('1');
    $("#tableName").val('');
    this._hide();
    this.autoReset = false;
    return false;
}